﻿using AutoMapper;
using IMES.Common.Domain.DariusModel;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;
using NPOI.SS.Formula.Functions;

namespace Darius.API.Application.Commands
{
    public class EmailCreateHandler : IRequestHandler<EmailCreateCommand, Result>
    {
        private readonly IBaseRepositorys<Emails> emailrepository;
        private readonly IMapper mapper;
        private readonly ILogger<EmailCreateHandler> logger;

        public EmailCreateHandler(IBaseRepositorys<Emails> emailrepository, IMapper mapper, ILogger<EmailCreateHandler> logger)
        {
            this.emailrepository = emailrepository;
            this.mapper = mapper;
            this.logger = logger;
        }
        /// <summary>
        /// 邮箱添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(EmailCreateCommand request, CancellationToken cancellationToken)
        {
            var result= new Result() { Code=(int)CodeEnum.add};
            var list =new Emails()
            {
                Email = request.Email,
                Code = request.Code,
                CreateTime = DateTime.Now,
                ExpireTime = DateTime.Now.AddMinutes(1)
            };
            result.Code = emailrepository.Add(list);
            return result;
        }
    }
}
